<template>
  <div>
    <Header :left="true" leftText="返回" title="关闭加严申请审批详情" v-if="show==true"/>
    <Header :left="true" leftText="返回" title="加严申请审批详情" v-if="show==false"/>
    <!-- 滑动区域，适应手机分辨率 -->
    <div class="textScroll">
      <div class="divMessage">
        <Field v-model="form.AddStrictIDList" :readonly="true" size="small" class="Field" center colon label="加严管控记录ID"
          label-width="110px" />
        <Field v-model="form.StrictDescription" :readonly="false" size="small" class="Field1" center colon label="加严管控描述"
          label-width="110px" rows="4" autosize type="textarea" />
      </div>
      <!-- 基本信息 -->
      <van-row style="margin-top: 10px">
        <van-col>
          <van-image width="40" height="30" style="margin-left: -10px" src="assets/block.png" />
        </van-col>
        <van-col class="message" style="margin-top: 5px">基本信息</van-col>
      </van-row>
      <div class="divMessage">
        <!-- <Field
          v-model="form.FactoryID"
          :readonly="true"
          size="small"
          class="Field"
          center
          colon
          label="工厂代码"
        /> -->
        <Field v-model="form.PLineID" :readonly="true" size="small" class="Field" center colon label="生产线"
          label-width="110px" />
        <Field v-model="form.RequestMan" :readonly="true" size="small" class="Field" center colon label="申请人"
          label-width="110px" />
        <Field v-model="form.ReqDescription" rows="2" autosize :readonly="true" type="textarea" label="申请描述:"
          placeholder="申请描述" class="Field1" label-width="110px" />
          <Field v-model="form.RequestReason" rows="2" autosize :readonly="true" type="textarea" label="申请关闭理由:"
          placeholder="申请关闭理由" class="Field1" label-width="110px" />
        <Field readonly="true" size="small" class="Field" center colon label="举证图片" label-width="110px" />
        <div style="margin-bottom: 15px;" v-if="equipRepairVo1.picList !== undefined &&
          equipRepairVo1.picList.length > 0
          ">
          <div style="margin-left: 15px;" v-for="(imgUrl, ks) in equipRepairVo1.picList" :key="ks">
            <div class="van-uploader__wrapper" style="float: left">
              <div class="van-uploader__preview">
                <div @click="picShow(ks)" class="van-image van-uploader__preview-image">
                  <img :src="imgUrl" class="van-image__img" />
                </div>
                <div class="van-uploader__preview-delete">
                  <i class="van-icon van-icon-cross"></i>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
      <!-- 主管审核 -->
      <!-- <van-row class="formstyle1">
        <van-col>
          <van-image width="40" height="30" style="margin-left: -10px" src="assets/block.png" />
        </van-col>
        <van-col class="divMessage" style="margin-top: 15px">主管审核</van-col>
      </van-row> -->
      <Field :readonly="true" size="small" class="Field" center colon label="主管审核" label-width="110px"
        style="font-size: 15px; font-weight: bold;" v-if="show==true" />
      <div class="divMessage" v-if="show==true">
        <Field v-model="form.CkeckedMemo" :readonly="false" name="处置建议" label="处置建议" placeholder="审核备注" rows="2" autosize
          type="textarea" maxlength="100" show-word-limit />
        <Field name="是否同意" class="formstyle" label="" v-if="this.status == false">
          <template #input>
            <van-radio-group v-model="QCLeaderAgreeValue" direction="horizontal" @change="changeAgreeValue">
              <van-radio name="1">通过关闭申请</van-radio>
              <van-radio name="0">拒绝关闭申请</van-radio>
            </van-radio-group>
          </template>
        </Field>
      </div>
      <!-- 操作历史 -->
      <!-- <van-row style="margin-top: 10px">
        <van-col>
          <van-image
            width="40"
            height="30"
            style="margin-left: -10px"
            src="assets/block.png"
          />
        </van-col>
        <van-col class="message" style="margin-top: 5px">操作历史</van-col>
      </van-row>
      <div class="divMessage">
        <Field
          v-model="form.Creator"
          :readonly="true"
          size="small"
          class="Field"
          center
          colon
          label="创建者"
        />
        <Field
          v-model="form.CreateDatetime"
          :readonly="true"
          size="small"
          class="Field"
          center
          colon
          label="创建日期时间"
        />
        <Field
          v-model="form.Modifytor"
          :readonly="true"
          size="small"
          class="Field"
          center
          colon
          label="修改者"
        />
        <Field
          v-model="form.ModifyDatetime"
          :readonly="true"
          size="small"
          class="Field"
          center
          colon
          label="最后修改日期"
        />
        <Field
          v-model="form.Id"
          :readonly="true"
          size="small"
          class="Field"
          center
          colon
          label="申请单ID"
        />
      </div> -->
      <!-- <div style="margin: 16px">
        <van-button color="#138087" round block type="info" native-type="submit"
          @click="selectDetails(form)">查看加严管控详情</van-button>
      </div> -->
      <div style="margin: 16px" v-if="this.status == false && show==true" >
        <van-button color="#138087" round block type="info" native-type="submit" @click="submitCheck()">确认提交</van-button>
      </div>
    </div>
  </div>
</template>
<script>
import {
  Icon,
  NoticeBar,
  Button,
  Row,
  Tag,
  Checkbox,
  Pagination,
  popup,
  Loading,
  Popup,
  Panel,
  ImagePreview,
  Toast,
  tab,
  tabs,
  Divider,
  Image as VanImage,
  Field,
  CellGroup,
  Cell,
  Picker,
  Uploader,
  Dialog,
  Col,
  RadioGroup,
  Radio,
} from "vant";
import { _httpClient as _httpClientApi } from "@/libs/api";
import { _httpClient } from "@/libs/apisie";
import { storage } from "@/libs/utils";
import {
  removeToken,
  getToken,
  setBaseApiFrefix,
  getBaseApiFrefix,
} from "@/libs/auth";
Vue.use(Cell);
Vue.use(CellGroup);
Vue.use(tab);
Vue.use(tabs);
Vue.use(Button);
Vue.use(Col);
Vue.use(Row);
Vue.use(Icon);
Vue.use(VanImage);
Vue.use(Divider);
Vue.use(Checkbox);
Vue.use(Pagination);
Vue.use(Panel);
Vue.use(Dialog);
Vue.use(Picker);
Vue.use(popup);
Vue.use(Uploader);
Vue.use(Loading);
Vue.use(Field);
Vue.use(RadioGroup);
Vue.use(Radio);
import Header from "@/components/header.vue";
import apicloud from "@/libs/apicloud";
export default {
  name: "tightclosesureitem",

  components: {
    Button,
    NoticeBar,
    Header,
    ImagePreview,
    Icon,
    Row,
    tab,
    popup,
    Popup,
    tabs,
    Tag,
    VanImage,
    Toast,
    Divider,
    Field,
    CellGroup,
    Cell,
    Uploader,
    Picker,
    Dialog,
    Col,
    RadioGroup,
    Radio,
  },

  data() {
    return {
      show:false,
      equipRepairVo1: {
        eqKey: null,
        equipName: "",
        equipCode: "",
        remark: null,
        picList: [],
        videoList: [],
        audioList: [],
        requestTime: this.getNowTime(),
        requestUser: "",
      },
      btnLoading: false,
      winName: "", //窗口名
      user: [], //当前登录用户

      form: [],
      faultTypes: [],
      stopReson: [],
      uploadSuccess: false,
      columnsDealType: [],
      columnsEmployee: [],
      columnsQProblem: [],
      columnsshift: [],
      showPickerEmployee: false,
      showPickerQProblem: false,
      item: {},
      valuepDealTypeName: "",
      EmployeeName: "",
      time: "",
      FactoryID: "",
      valuepShiftName: "",
      CheckTypeName: "",
      QProblemName: "",
      valueteamid: "",
      nowDate: "",
      EmployeeID: "",
      result: [],
      //领班
      QCLeaderAgreeValue: "",
      //带版主管
      TeamLeaderAgreeValue: "",
      //质量负责人
      QCManagerAgreeValue: "",
      //生产部门负责人
      PrdManagerAgreeValue: "",
      //利润点负责人
      FactoryManagerAgreeValue: "",
      //当前状态
      status: "",
      //是否显示人员
      showEmployee: false,
    };
  },
  created: function () {
    this.user = JSON.parse(storage.get("user"));
    let oldHight = api.winWidth;
    this.screenWidth = oldHight;
    this.form = api.pageParam.item;
    this.show = api.pageParam.show;
    //this.equipRepairVo1.picList=api.pageParam.item.ImageURL;
    var n = api.pageParam.item.ImageURL.split(",");
    for (let index = 0; index < n.length; index++) {
      this.equipRepairVo1.picList.push(n[index]);
    }
    //alert(JSON.stringify(api.pageParam.item));
    this.status = this.form.Checked;
    this.nowDate = this.getNowTime();
  },
  methods: {
    getNowTimeplus() {
      let dateTime
      let yy = new Date().getFullYear()
      let mm = new Date().getMonth() + 1
      let dd = new Date().getDate()
      let hh = new Date().getHours()
      let mf = new Date().getMinutes() < 10 ? '0' + new Date().getMinutes()
        :
        new Date().getMinutes()
      let ss = new Date().getSeconds() < 10 ? '0' + new Date().getSeconds()
        :
        new Date().getSeconds()
      dateTime = yy + '-' + mm + '-' + dd + ' ' + hh + ':' + mf + ':' + ss
      return dateTime
    },
    async sendmessage() {
      let _this = this;

      let eventDescription = "";
      let eventDatetime = _this.getNowTimeplus();
      let eventTypeID = "N3";
      let eventID = "";
      let messageContent = "";
      let msgContentTypeID = "";
      let pLineID = "";
      let machineID = "";
      let pShiftID = "";
      let teamID = "";
      let pOrderID = "";
      let productionBarcode = "";
      let materialBarcode = "";
      let relatedEmployee = "";
      let messageStatus = "";
      let processBatchID = "";
      let beginDatetime = _this.getNowTimeplus();
      let sendFinished = false;
      let closed = false;

      msgContentTypeID = "ADS08";
      eventID = "ADS08";
      eventDescription = "加严关闭申请单:" + _this.form.Id + "已审批，未被通过！";
      messageContent = "加严关闭申请单:" + _this.form.Id + "已审批，未被通过！";


      let bodysss = {
        eventDescription: eventDescription,
        eventDatetime: eventDatetime,
        eventTypeID: eventTypeID,
        eventID: eventID,
        messageContent: messageContent,
        msgContentTypeID: msgContentTypeID,
        factoryID: "TC00",
        pLineID: pLineID,
        machineID: machineID,
        pShiftID: pShiftID,
        teamID: teamID,
        pOrderID: pOrderID,
        productionBarcode: productionBarcode,
        materialBarcode: materialBarcode,
        relatedEmployee: relatedEmployee,
        messageStatus: messageStatus,
        processBatchID: processBatchID,
        beginDatetime: beginDatetime,
        sendFinished: sendFinished,
        closed: closed
      };
      try {
        let res = await _httpClient.post(
          _httpClient.getApiPrefix() + "/RealtimeEventMessage/SaveEntity",
          {
            body: bodysss,
          }
        );
        //alert(JSON.stringify(res));
        if (res.Message == null) {
          Toast.clear();
          Toast.success("发送成功");

          api.openWin({
            name: "tightclosesure",
            url: "./tightenup-tightclosesure.html",
            reload: true,
          });
          setTimeout(function () {
            _this.$ac.closeWin();
          }, 2000);

        } else {
          Toast.clear();
          Toast.fail("发送失败");
        }
      } catch (e) {
        Toast.fail(JSON.stringify(e));
      }
    },
    async sendmessage2() {
      let _this = this;

      let eventDescription = "";
      let eventDatetime = _this.getNowTimeplus();
      let eventTypeID = "N3";
      let eventID = "";
      let messageContent = "";
      let msgContentTypeID = "";
      let pLineID = "";
      let machineID = "";
      let pShiftID = "";
      let teamID = "";
      let pOrderID = "";
      let productionBarcode = "";
      let materialBarcode = "";
      let relatedEmployee = "";
      let messageStatus = "";
      let processBatchID = "";
      let beginDatetime = _this.getNowTimeplus();
      let sendFinished = false;
      let closed = false;

      msgContentTypeID = "ADS07";
      eventID = "ADS07";
      eventDescription = "加严关闭申请单:" + _this.form.Id + "已审批，已经通过，并关闭了加严管控";
      messageContent = "加严关闭申请单:" + _this.form.Id + "已审批，已经通过，并关闭了加严管控";


      let bodysss = {
        eventDescription: eventDescription,
        eventDatetime: eventDatetime,
        eventTypeID: eventTypeID,
        eventID: eventID,
        messageContent: messageContent,
        msgContentTypeID: msgContentTypeID,
        factoryID: "TC00",
        pLineID: pLineID,
        machineID: machineID,
        pShiftID: pShiftID,
        teamID: teamID,
        pOrderID: pOrderID,
        productionBarcode: productionBarcode,
        materialBarcode: materialBarcode,
        relatedEmployee: relatedEmployee,
        messageStatus: messageStatus,
        processBatchID: processBatchID,
        beginDatetime: beginDatetime,
        sendFinished: sendFinished,
        closed: closed
      };
      try {
        let res = await _httpClient.post(
          _httpClient.getApiPrefix() + "/RealtimeEventMessage/SaveEntity",
          {
            body: bodysss,
          }
        );
        //alert(JSON.stringify(res));
        if (res.Message == null) {
          Toast.clear();
          Toast.success("发送成功");

          api.openWin({
            name: "tightclosesure",
            url: "./tightenup-tightclosesure.html",
            reload: true,
          });
          setTimeout(function () {
            _this.$ac.closeWin();
          }, 2000);

        } else {
          Toast.clear();
          Toast.fail("发送失败");
        }
      } catch (e) {
        Toast.fail(JSON.stringify(e));
      }
    },
    picShow(pIndex) {
      ImagePreview({
        images: this.equipRepairVo1.picList || [],
        showIndicators: true,
        startPosition: pIndex || 0,
        showIndex: false,
      });
    },
    //提交审批
    submitCheck() {
      var body = {};
      body = this.form;
      //body.Id = this.form.Id;
      //body.QCLeaderAgree = this.form.QCLeaderAgree;
      //body.QCLeaderMemo = this.form.QCLeaderMemo;
      //body.QCLeaderUserID = this.user.userId;
      //body.QCLeaderCheckDatetime = this.nowDate;
      //body.QCLeaderChecked = true;
      this.SaveCheckEntity(body);
    },
    //确认
    async selectDetails(item) {
      api.openWin({
        name: "heyu6",
        url: "./employee-heyu6.html",
        pageParam: {
          item: item,
        },
        reload: true,
      });
    },
    async SaveCheckEntity(body) {
      let _this = this;
      Toast.loading({
        mask: true,
        forbidClick: true,
        duration: 0,
        message: "请稍等...",
      });
      try {
        let res = await _httpClient.post(
          _httpClient.getApiPrefix() + "/AddStrictCloseRequest/SaveEntity",

          {
            body: body,
          }
        );
        if (res.Message != null) {
          //message不为空,有报错信息，打卡失败 暂时这样判断
          Toast.clear();
          Toast.fail("保存失败,请核对信息！");
        } else {
          //打卡成功
          Toast.clear();
          Toast.success("保存成功！");
          if(this.QCLeaderAgreeValue=="1"){
            _this.sendmessage2();
          }else{
            _this.sendmessage();
          }
          
        
        }
      } catch (e) {
        Toast.fail(JSON.stringify(e));
      }
    },
    changeAgreeValue() {
      this.form.CheckedMan = this.user.userName;
      this.form.Modifytor = this.user.userName;
      this.form.CheckedDatetime = this.getNowTime();
      this.form.ModifyDatetime = this.getNowTime();
      this.form.Checked = true;
      //如果合格 隐藏页面 直接提交
      if (this.QCLeaderAgreeValue == "1") {
        this.form.Passed = true;
        this.form.CkeckedMemo =
          this.getNowTime() +
          ":" +
          "质量部负责人:" +
          this.user.employeeName +
          "已通过关闭加严申请并关闭了加严管控!";
      } else if (this.QCLeaderAgreeValue == "0") {
        //若不同意
        this.form.Passed = false;
        this.form.CkeckedMemo =
          this.getNowTime() +
          ":" +
          "质量部负责人:" +
          this.user.employeeName +
          "拒绝了关闭加严申请，产品质量还不符合质量要求，需要继续加严管控!";
      }
    },
    // 获取当前时间
    getNowTime() {
      let dateTime;
      let yy = new Date().getFullYear();
      let mm = new Date().getMonth() + 1;
      let dd = new Date().getDate();
      let hh = new Date().getHours();
      let mf =
        new Date().getMinutes() < 10
          ? "0" + new Date().getMinutes()
          : new Date().getMinutes();
      let ss =
        new Date().getSeconds() < 10
          ? "0" + new Date().getSeconds()
          : new Date().getSeconds();
      dateTime = yy + "-" + mm + "-" + dd + " " + hh + ":" + mf + ":" + ss;
      return dateTime;
    },
  },
};
</script>
<style>
html,
body {
  font-family: "Open Sans", sans-serif;
  background-color: White;
}

.mg5 {
  margin-right: 5px;
}

.wrapper {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
}

.container.dwo {
  display: flex;
  justify-content: center;
  align-items: center;
}

.tag_margin {
  margin: 2px 5px;
}

.card_under {
  height: 100%;
  width: 100%;
  margin: auto;
  background: #ffffff;
  border-radius: 25px;
  box-shadow: 0 0px 0px rgba(0, 0, 0, 0.3);
}

.formstyle {
  margin-top: 8px;
  font-size: 15px;
  font-weight: bold;
  display: flex;
  align-items: center;
}

.formstyle1 {
  margin-top: 15px;
  font-size: 15px;
  font-weight: bold;
  align-items: center;
}

.confirmReport {
  position: fixed;
  right: 5px;
  bottom: 24px;
  width: 48%;
  height: 40px;
  font-size: 12px;
}

.concelReport {
  position: fixed;
  left: 5px;
  bottom: 24px;
  width: 48%;
  height: 40px;
  font-size: 12px;
}

.card_icon {
  text-align: center;
  /* position: absolute; */
  height: 8rem;
  width: 80%;
  margin: 12% 10%;
  background: rgba(35, 180, 237, 1);
  border-radius: 25px;
  box-shadow: 0 10px 50px rgba(0, 0, 0, 0.3);
}

.text {
  font-size: 18px;
  color: #4e4a67;
  margin: 8px auto auto 20px;
  line-height: 1.5rem;
  text-align: justify;
  font-weight: 600;
}

.text_small {
  font-size: 16px;
  color: red;
  margin: 8px auto auto 20px;
  line-height: 1.5rem;
  text-align: justify;
  font-weight: 700;
}

.text_scan {
  font-size: 16px;
  color: #4e4a67;
  margin: auto auto auto 20px;
  line-height: 1.5em;
  text-align: justify;
}

.textScroll {
  display: inline-block;
  position: fixed;
  top: 5rem;
  bottom: 0px;
  overflow: scroll;
  right: 0;
  width: 100%;
  margin-bottom: 0rem;
  z-index: 1;
}

.divStyle {
  /* border: 1px solid #dcdcdc; */
  border-top-width: 3px;
  border-left-width: 3px;
  margin-left: 3px;
  margin-right: 3px;
  margin-top: 4px;
}

.buttonRight {
  position: fixed;
  margin-top: -40px;
  right: 15px;
  width: 90px;
  height: 40px;
  background-color: #1c6c8d;
  border-color: #1c6c8d;
}

.buttonLeft {
  position: fixed;
  margin-top: -40px;
  right: 110px;
  width: 90px;
  height: 40px;
  background-color: #1c6c8d;
  border-color: #1c6c8d;
}
</style>
